#include "ServerHandler.h"
#include "ActionThread.h"
#include <QMessageBox>

ServerHandler::ServerHandler(QObject *parent) :
	QTcpServer(parent),
	_logger(NULL),
	_userManager(new UserManager())
{
}

void ServerHandler::setLogger(Logger *logger){
	_logger = logger;
}

void ServerHandler::incomingConnection(int socketDescriptor)
{
	ActionThread *thread = new ActionThread(socketDescriptor, _userManager, this);
	connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));

	if(_logger){
		connect(thread,SIGNAL(writeData(QString)),_logger,SLOT(writeLine(QString)));
	}

	thread->start();
}
